﻿//using System;
//using System.Collections.Generic;
//using System.Data.Entity;

//using ApplicationBoilerplate.DataProvider;

//namespace MVCBootstrap.EntityFramework {

//    public class RepositoryProvider : IRepositoryProvider {
//        private readonly RepositoryFactories repositoryFactories;

//        protected Dictionary<Type, Object> Repositories { get; private set; }

//        public RepositoryProvider(RepositoryFactories repositoryFactories) {
//            this.repositoryFactories = repositoryFactories;
//            this.Repositories = new Dictionary<Type, Object>();
//        }

//        public DbContext DbContext { get; set; }

//        public IRepository<T> GetRepositoryForEntityType<T>() where T : class {
//            return this.GetRepository<IRepository<T>>(
//                this.repositoryFactories.GetRepositoryFactoryForEntityType<T>());
//        }

//        public virtual T GetRepository<T>(Func<DbContext, Object> factory = null) where T : class {
//            Object repoObj;
//            Repositories.TryGetValue(typeof(T), out repoObj);
//            if (repoObj != null) {
//                return (T)repoObj;
//            }

//            return this.MakeRepository<T>(factory, DbContext);
//        }

//        protected virtual T MakeRepository<T>(Func<DbContext, Object> factory, DbContext dbContext) {
//            var f = factory ?? this.repositoryFactories.GetRepositoryFactory<T>();
//            if (f == null) {
//                throw new NotImplementedException("No factory for repository type, " + typeof(T).FullName);
//            }
//            var repo = (T)f(dbContext);
//            this.Repositories[typeof(T)] = repo;
//            return repo;
//        }

//        public void SetRepository<T>(T repository) {
//            this.Repositories[typeof(T)] = repository;
//        }
//    }
//}